import requests
from utils.time_tool.time_control import Getdate


def push_message(webhook, message_content):
    # 发送报告
    requests.post(url=webhook, json=message_content, verify=False)


def parse_prometheus_data(file_path):
    # 或者测试报告的相关信息
    content = {}
    with open(file_path) as f:
        for line in f.readlines():
            launch_name, num = line.strip('\n').split(' ')
            content[launch_name] = num
    return content


def generate_message_content(content, description, report_url):
    # 构建推送至飞书的报告的样式
    passed_num = content['launch_status_passed']
    failed_num = content['launch_status_failed']
    broken_num = content['launch_status_broken']
    skipped_num = content['launch_status_skipped']
    case_num = content['launch_retries_run']
    message_content = {
        "msg_type": "text",
        "content": {
            "text": f"自动化执行结果：\n日期：{Getdate().getCurrentday()} {Getdate().getWeekdayToday()}\n"
                    f"项目描述：{description}\n"
                    f"通过数量：{passed_num}\n"
                    f"失败数量：{failed_num}\n"
                    f"阻塞数量：{broken_num}\n"
                    f"跳过数量：{skipped_num}\n"
                    f"总数量：{case_num}\n"
                    f"通过率：{int(passed_num) / int(int(case_num) - int(skipped_num)) * 100}% \n"
                    f"测试报告：{report_url}\n"

        }
    }
    return message_content


if __name__ == '__main__':
    # python main.py --env=pro --mark=gmv
    # python send_dingding_gmv.py --type=test
    pass
